var mass = [];
var mass2 = [];

	function ValidatePassword() {
		if (mass[1] != mass[2]) {
			return false;
		}
		if (mass[1].length < 8) {
			return false;
		}
		return true;
	}
	function CheckFieldsForEmpty() {
		for ( var i in mass) {
			if (mass[i] == "") {
				document.getElementById("error").innerHTML = "<div class=\"alert alert-danger\"><a class=\"close\" href=\"#\" data-dismiss=\"alert\"></a>Reg form: empty field(s)!</div>";
				return false;
			}
		}
		return true;
	}
	function init(){
		mass[0] = document.getElementsByName("login");
		mass[1] = document.getElementById("password1").value;
		mass[2] = document.getElementById("password2").value;
		mass[3] = document.getElementById("username").value;
		mass[4] = document.getElementById("mail").value;
		mass2[0] = "login";
		mass2[1] = "password1";
		mass2[2] = "password2";
		mass2[3] = "username";
		mass2[4] = "mail";
		mass2[5] = "password do not match!";
		mass2[6] = "minimum 8 symboled password!";
		mass2[7] = "empty field!";
	}
	function Validate() {
		init();
		isValid = new Boolean(true);
		isValid = CheckFieldsForEmpty(); 
		isValid = isValid && ValidatePassword();
		if (isValid)
			document.reg.submit();
		//window.location.replace("http://www.stackoverflow.com");
	}